/*
 * Copyright 2009, Qys Creations 
 * 
 *  This file is part of Chameleon DB.
 *
 *  Chameleon DB is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Chameleon DB is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Chameleon DB.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * */


import java.util.regex.Pattern;

public class db_statement_show_tables implements db_interface_statement {

	public String[] oTokens = new String[2];
	public Pattern[] oRegex = new Pattern[0];
	private db_util_parser oUtilParser = null;

	db_statement_show_tables() {
		oTokens[0] = "SHOW";
		oTokens[1] = "TABLES";
		oUtilParser = new db_util_parser(oTokens);
	}
	public db_interface_parse_result parse(String sSQL) {

		oUtilParser.restart(sSQL);
		int iRes = query();

		if (oUtilParser.sQuery.trim().length() > 0 && iRes == 0)
			iRes = -1;

		db_parse_result_show_tables oRes = new db_parse_result_show_tables();
		oRes.set_result(iRes);
		return oRes;
	}

	public int query() {
		if (!oUtilParser.matchReplace(oUtilParser.sQuery, oTokens[0]))
			return -2;
		
		if (!oUtilParser.matchReplaceNoSpace(oUtilParser.sQuery, oTokens[1]))
			return -2;
		
		return 0;
	}
}
